<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <style type="text/css">
        .uploadImg {
            border: none;
            width: 150px;
            display: block;
            margin-top: 10px;
        }
        .info{
            font-size: 12px;
            color: rgba(0,0,0,0.5);
        }
    </style>
</head>
<body>

<form class="layui-form" lay-filter="layuiadmin-form-role" id="layuiadmin-form-role" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="rec_title" value="" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">简要介绍</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入简要介绍" class="layui-textarea" name="rec_description"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">缩略图</label>

        <div class="layui-input-block">
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="upload">上传图片</button>
                <p class="info">建议尺寸：轮播图（1390*400px）、推广图（290*90px）</p>
                <img id="demo1" class="uploadImg">
                <input type="hidden" name="rec_image" id="rec_image">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">跳转地址</label>
        <div class="layui-input-block">
            <input type="text" name="rec_url" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input id="" type="number" name="rec_order" value="" placeholder="请输入整数，默认序号为2，序号越小排序越靠前"
                   class="layui-input">
        </div>
    </div>
    <input type="hidden" name="rec_role" value="{$rec_role}">
    <div class="layui-form-item layui-hide">
        <button class="layui-btn" lay-submit lay-filter="add" id="add">提交</button>
    </div>

</form>
<script src="/static/layuiadmin/lib/jquery.min.js"></script>
<script src="/static/layuiadmin/layui/layui.js"></script>

<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', "upload"], function () {
        var $ = layui.$
            , form = layui.form
            , upload = layui.upload;
        var uploadInst = upload.render({
            elem: '#upload'
            , url: "{:url('admin/recommend/uploadImg')}"
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                var src = res.data.src;
                $("#rec_image").val(src);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });


    });
</script>
</body>
</html>
